﻿/**
 *	\file		lxpref_route_msg.hxx
 *	\date		(2014-12-17 22:59:39)/(2014-12-17 22:59:39)
 *-----------------------------------------------------------------------------
 *	\brief
 *	\version	1.0.0.1
 *	\author		Nick Shallery	(nicknide@gmail.com)
 *	\copyright	YOU HAVE ALL LEFT WITH THIS CODE WHILE YOU KEEP COMMENT IN EVERY COPY.
 *-----------------------------------------------------------------------------
**/

#if			!defined(__LXPREF__ROUTE_MSG__HXX__NICK__K_IN_G__)
#define		__LXPREF__ROUTE_MSG__HXX__NICK__K_IN_G__

#if			!defined(__LOLIX__LOLIX_TYPE__K_IN_G__)
#	include	<lolix/lolix_type.h>
#endif	//	!defined(__LOLIX__LOLIX_TYPE__K_IN_G__)

#if			!defined(__LOLIX__TOY__STD_VECTOR__NICK__K_IN_G__)
#	include	<lolix/toy/std_vector.hpp>
#endif	//	!defined(__LOLIX__TOY__STD_VECTOR__NICK__K_IN_G__)

#if			!defined(__LOLIX__TOY__STD_STRING__NICK__K_IN_G__)
#	include	<lolix/toy/std_string.hpp>
#endif	//	!defined(__LOLIX__TOY__STD_STRING__NICK__K_IN_G__)

#if			!defined(__LOLIX_TOY__ARCHIVE__NICK__K_IN_G__)
#	include	<lolix/toy/archive.hpp>
#endif	//	!defined(__LOLIX_TOY__ARCHIVE__NICK__K_IN_G__)

#define		LOLIX_DEF__ARC_SUPPORT_VECTOR
#include	<lolix/toy/archive_supported_UDT.hpp>


#include	"../lxpref/lxpref.h"

namespace lxpref{namespace message{

	lolix::size_type GetNameCount(unsigned mask);
	enum PREF_MSG_TYPE LOLIX_ETYPE(lolix::lx_u32)
	{	MSG_TYPE_INFO
	,	MSG_TYPE_QUERY_NAME
	,	MSG_TYPE_QUEST_NAME
	};

	template<typename _Talc>
	struct packet_header
	{
		PREF_MSG_TYPE msg_type;
		lolix::toy::vector<unsigned char, _Talc> dat;
		LOLIX_INLINE_CALL packet_header(void){}
		LOLIX_INLINE_CALL packet_header(PREF_MSG_TYPE mtype):msg_type(mtype){}
		template<typename _Tp0> LOLIX_INLINE_CALL packet_header(_Tp0 const& tp0):dat(tp0){}
		template<typename _Tp0> LOLIX_INLINE_CALL packet_header(PREF_MSG_TYPE mtype, _Tp0 const& tp0):msg_type(mtype), dat(tp0){}
		template<typename _TyArc>
		LOLIX_INLINE_CALL void write(_TyArc& arc)const
		{
			arc << (lolix::toy::size_value)msg_type
				<< dat;
		}

		template<typename _TyArc>
		LOLIX_INLINE_CALL void read(_TyArc& arc)
		{
			lolix::toy::size_value sv;
			arc >> sv
				>> dat;
			if ( LOLIX_IS_ERROR(arc.get_eh().err()) )
				return;
			msg_type = sv;
		}
	};



	//typedef event_info post_pref_info;
	//struct post_pref_info
	//	: public event_info
	//{
	//	LOLIX_INLINE_CALL post_pref_info(void)
	//	{
	//	}

	//	LOLIX_INLINE_CALL post_pref_info(event_info const& evtinf)
	//		: event_info(evtinf)
	//	{
	//	}

	//	//template<typename _Tarc>
	//	//inline void read(_Tarc& arc)
	//	//{
	//	//	lolix::toy::size_value st;
	//	//	arc >> st; section_type = st;
	//	//	arc >> enter_time_tick;	//	性能分析的进入时间
	//	//	arc >> leave_time_tick;	//	性能分析函数离开的时间（于enter_time_tick差值为性能分析内部开销)
	//	//	arc >> thread_id;
	//	//	arc >> st; param_cnt = st;
	//	//	for ( lolix::size_type i = 0; i != param_cnt; ++i )
	//	//	{
	//	//		lolix::toy::size_value sv;
	//	//		arc >> sv;

	//	//		lolix::size_type val = sv;
	//	//		str_param[i] = (lolix::lx_wchar*)val;
	//	//	}
	//	//}

	//	//template<typename _Tarc>
	//	//inline void write(_Tarc& arc)const
	//	//{
	//	//	arc << lolix::toy::size_value(section_type);
	//	//	arc << enter_time_tick;
	//	//	arc << leave_time_tick;
	//	//	arc << thread_id;
	//	//	arc << lolix::toy::size_value(param_cnt);
	//	//	for ( lolix::size_type i = 0; i != param_cnt; ++i )
	//	//		arc << lolix::toy::size_value((lolix::size_type)str_param[i]);
	//	//}
	//};

	template<typename _TAlc>
	struct query_names
	{
		lolix::toy::vector<lolix::toy::size_value, _TAlc> names_address;
		LOLIX_INLINE_CALL query_names(void){}
		template<typename _Tp0>
		LOLIX_INLINE_CALL query_names(_Tp0 const& tp0):names_address(tp0){}

		template<typename _Tarc>
		inline void read(_Tarc& arc)
		{
			arc >> names_address;
		}

		template<typename _Tarc>
		inline void write(_Tarc& arc)const
		{
			arc << this->names_address;
		}
	};


	template<typename _TAlc>
	struct response_names
	{
		lolix::toy::vector<lolix::toy::size_value, _TAlc> name_ptr;
		lolix::toy::vector<lolix::toy::size_value, _TAlc> name_idx;
		lolix::toy::vector<lolix::toy::size_value, _TAlc> name_len;
		lolix::toy::vector<lolix::lx_wchar, _TAlc> names;
		LOLIX_INLINE_CALL response_names(void){}
		template<typename _Talc> response_names(_Talc const& alc):names(alc), name_ptr(alc), name_idx(alc), name_len(alc){}
		template<typename _Tarc> LOLIX_INLINE_CALL void read(_Tarc& arc)
		{
			arc >> names >> name_ptr >> name_idx >> name_len;
		}

		template<typename _Tarc> LOLIX_INLINE_CALL void write(_Tarc& arc)const
		{
			arc << names << name_ptr << name_idx << name_len;
		}
	};
}}

namespace lolix{namespace toy{

	template<typename _Teh>
	LOLIX_INLINE_CALL archive<_Teh>& operator << (archive<_Teh>& arc, lxpref::event_info const& evt_inf)
	{
		arc << lolix::toy::size_value(evt_inf.section_type);
		arc << evt_inf.enter_time_tick;
		arc << evt_inf.leave_time_tick;
		arc << evt_inf.thread_id;
		arc << lolix::toy::size_value(evt_inf.param_cnt);
		for ( lolix::size_type i = 0; i != evt_inf.param_cnt; ++i )
			arc << lolix::toy::size_value((lolix::size_type)evt_inf.str_param[i]);
		return arc;
	}
	template<typename _Teh>
	LOLIX_INLINE_CALL archive<_Teh>& operator >> (archive<_Teh>& arc, lxpref::event_info& evt_inf)
	{
		lolix::toy::size_value st;
		arc >> st; evt_inf.section_type = st;
		arc >> evt_inf.enter_time_tick;	//	性能分析的进入时间
		arc >> evt_inf.leave_time_tick;	//	性能分析函数离开的时间（于enter_time_tick差值为性能分析内部开销)
		arc >> evt_inf.thread_id;
		arc >> st; evt_inf.param_cnt = st;
		for ( lolix::size_type i = 0; i != evt_inf.param_cnt; ++i )
		{
			lolix::toy::size_value sv;
			arc >> sv;

			lolix::size_type val = sv;
			evt_inf.str_param[i] = (lolix::lx_wchar*)val;
		}
		return arc;
	}
}}


#endif	//	!defined(__LXPREF__ROUTE_MSG__HXX__NICK__K_IN_G__)
